package com.sczmgk.hotline_pzh.utils;

import android.view.View;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class CompanyNameUtils {
	/**
	 * 切割公司名与切割坐标共用    以符号 "/"切割
	 * @param companyNamesStr
	 * @return
	 */
	public static  String[] splitCompanyNames(String companyNamesStr){
		if(Tools.isEmpty(companyNamesStr)){
			return new String[]{};
		}
		String[] companyNames = companyNamesStr.split("/");
		return companyNames;
	}
	
	
	/**
	 * 设置公司名字,如果没有公司名就不显示
	 * @param companynames   公司名字符串  如：公司一/公司二/公司三
	 * @param mName01
	 * @param mName02
	 * @param mName03
	 */
	public static void setCompanyName(String companynames,TextView mName01,TextView mName02,TextView mName03){

        if(Tools.isEmpty(companynames)){
            return ;
        }
		String[] splitCompanyNames = splitCompanyNames(companynames);
		List<String> names = new ArrayList<String>();
		for (int i = 0; i < splitCompanyNames.length; i++) {
			if(!Tools.isEmpty(splitCompanyNames[i])){
				names.add(splitCompanyNames[i]);
			}
		}
		if(names.size()>1){
			for (int i = 0; i < names.size(); i++) {
				switch (i) {
				case 0:
					mName01.setVisibility(View.VISIBLE);
					mName01.setText("1、"+names.get(i));
					break;
				case 1:
					mName02.setVisibility(View.VISIBLE);
					mName02.setText("2、"+names.get(i));
					break;
				case 2:
					mName03.setVisibility(View.VISIBLE);
					mName03.setText("3、"+names.get(i));
					break;
					
				default:
					break;
				} 
			}
		}else{
			mName01.setVisibility(View.VISIBLE);
			mName01.setText(" "+names.get(0));
		}
	}
	
	/**
	 * 格式 化公司名的字符串
	 * @param name1   公司名一
	 * @param name2  公司名二
	 * @param name3  公司名三
	 * @return      公司名一/公司名二/公司名三
	 */
	public static String getCompanyNames(String name1,String name2,String name3){

		String[] strArr = new String[]{name1,name2,name3};
        //有公司名的数量
		int count=0;
		int count1 = 0;
		for(int i = 0; i < strArr.length; i++){
			if(!Tools.isEmpty(strArr[i])){
				count++;
			}
		}
		String[] strArr2 = new String[count];
		for(int j = 0; j < strArr.length; j++){
			if(!Tools.isEmpty(strArr[j])){
				strArr2[count1] = strArr[j];
				count1++;
			}
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < strArr2.length; i++) {
			sb.append(strArr[i]);
			sb.append("/");
		}
		String requestStr =  sb.toString();
		requestStr = requestStr.substring(0, requestStr.length() - 1);
		return requestStr;
	}
}
